﻿using System;
using System.Reflection;
using Mono.Cecil;
using UnityEditor;
using UnityEngine;

namespace ProjScan.Tools
{
	// Token: 0x0200015E RID: 350
	internal class AssemblyTools
	{
		// Token: 0x06000C8B RID: 3211 RVA: 0x00036E08 File Offset: 0x00035008
		private AssemblyTools()
		{
			this.gameObjectAssembly = typeof(GameObject).Assembly;
			this.editorWindowAssembly = typeof(EditorWindow).Assembly;
		}

		// Token: 0x06000C8C RID: 3212 RVA: 0x00036E58 File Offset: 0x00035058
		public string GetAppendFullName(TypeDefinition typeDefinition)
		{
			bool flag = !string.IsNullOrEmpty(typeDefinition.FullName);
			string result;
			if (flag)
			{
				result = "$" + typeDefinition.FullName;
			}
			else
			{
				result = string.Empty;
			}
			return result;
		}

		// Token: 0x06000C8D RID: 3213 RVA: 0x00036E98 File Offset: 0x00035098
		public Type GetTypeOne(string typeName)
		{
			return null;
		}

		// Token: 0x06000C8E RID: 3214 RVA: 0x00036E98 File Offset: 0x00035098
		public Type GetTypeTwo(string typeName)
		{
			return null;
		}

		// Token: 0x06000C8F RID: 3215 RVA: 0x00036EAC File Offset: 0x000350AC
		public object GetPropertyValue(object sourceObject, string propertyName)
		{
			bool flag = sourceObject != null;
			if (flag)
			{
				PropertyInfo property = sourceObject.GetType().GetProperty(propertyName);
				bool flag2 = property != null;
				if (flag2)
				{
					return property.GetValue(sourceObject, null);
				}
				ScanLog.Instance.LogInfo("Reflect: can not found:" + propertyName + " from obj with type " + sourceObject.GetType().FullName);
			}
			return null;
		}

		// Token: 0x06000C90 RID: 3216 RVA: 0x00036F14 File Offset: 0x00035114
		public void SetPropertyValue(object sourceObject, string propertyName, object propertyValue)
		{
			bool flag = sourceObject != null;
			if (flag)
			{
				PropertyInfo property = sourceObject.GetType().GetProperty(propertyName);
				bool flag2 = property != null;
				if (flag2)
				{
					property.SetValue(sourceObject, propertyValue, null);
				}
				else
				{
					ScanLog.Instance.LogInfo("Reflect: can not found:" + propertyName + " from obj with type " + sourceObject.GetType().FullName);
				}
			}
		}

		// Token: 0x06000C91 RID: 3217 RVA: 0x00036F7C File Offset: 0x0003517C
		public object GetStaticPropertyValue(Type sourceType, string propertyName)
		{
			PropertyInfo property = sourceType.GetProperty(propertyName);
			bool flag = property != null;
			object result;
			if (flag)
			{
				result = property.GetValue(null, null);
			}
			else
			{
				ScanLog.Instance.LogInfo("Reflect: can not found:" + propertyName + " from type " + sourceType.FullName);
				result = null;
			}
			return result;
		}

		// Token: 0x06000C92 RID: 3218 RVA: 0x00036FD0 File Offset: 0x000351D0
		public object GetFieldValue(object sourceObject, string fieldName)
		{
			bool flag = sourceObject != null;
			if (flag)
			{
				FieldInfo field = sourceObject.GetType().GetField(fieldName);
				bool flag2 = field != null;
				if (flag2)
				{
					return field.GetValue(sourceObject);
				}
				ScanLog.Instance.LogInfo("Reflect: can not found:" + fieldName + " from obj with type " + sourceObject.GetType().FullName);
			}
			return null;
		}

		// Token: 0x06000C93 RID: 3219 RVA: 0x00037038 File Offset: 0x00035238
		public object GetStaticFieldValue(Type sourceType, string fieldName)
		{
			FieldInfo field = sourceType.GetField(fieldName);
			bool flag = field != null;
			object result;
			if (flag)
			{
				result = field.GetValue(null);
			}
			else
			{
				ScanLog.Instance.LogInfo("Reflect: can not found:" + fieldName + " from type " + sourceType.FullName);
				result = null;
			}
			return result;
		}

		// Token: 0x06000C94 RID: 3220 RVA: 0x0003708C File Offset: 0x0003528C
		public bool TryInvokeMethod(Type sourceType, string methodName, out object result, object[] parameters)
		{
			result = null;
			MethodInfo method = sourceType.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			bool flag = method == null;
			bool result2;
			if (flag)
			{
				result2 = false;
			}
			else
			{
				try
				{
					result = method.Invoke(null, parameters);
				}
				catch (Exception)
				{
					return false;
				}
				result2 = true;
			}
			return result2;
		}

		// Token: 0x06000C95 RID: 3221 RVA: 0x000370E4 File Offset: 0x000352E4
		public bool TryGetMethodResult<T>(string typeName, string methodName, out T result, params object[] parameters)
		{
			result = default(T);
			Type type = Assembly.Load("UnityEditor").GetType(typeName);
			bool flag = type == null;
			bool result2;
			if (flag)
			{
				result2 = false;
			}
			else
			{
				MethodInfo methodInfo = null;
				try
				{
					methodInfo = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				}
				catch (NullReferenceException ex)
				{
					ScanLog.Instance.LogInfo(ex.Message + "\n" + ex.StackTrace);
				}
				bool flag2 = methodInfo == null;
				if (flag2)
				{
					result2 = false;
				}
				else
				{
					try
					{
						result = (T)((object)methodInfo.Invoke(null, parameters));
					}
					catch (Exception)
					{
						return false;
					}
					result2 = true;
				}
			}
			return result2;
		}

		// Token: 0x06000C96 RID: 3222 RVA: 0x000371A8 File Offset: 0x000353A8
		public bool TryInvokeUnityEditorMethod(string typeName, string methodName, params object[] parameters)
		{
			Type type = Assembly.Load("UnityEditor").GetType(typeName);
			bool flag = type == null;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				MethodInfo method = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
				bool flag2 = method == null;
				if (flag2)
				{
					result = false;
				}
				else
				{
					try
					{
						method.Invoke(null, parameters);
					}
					catch (Exception)
					{
						return false;
					}
					result = true;
				}
			}
			return result;
		}

		// Token: 0x040007A6 RID: 1958
		public static readonly AssemblyTools I = new AssemblyTools();

		// Token: 0x040007A7 RID: 1959
		private Assembly gameObjectAssembly = null;

		// Token: 0x040007A8 RID: 1960
		private Assembly editorWindowAssembly = null;
	}
}
